package cn.pomelo.secondskill.service.impl;

import cn.hutool.core.lang.ObjectId;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.pomelo.secondskill.model.UserInfo;
import cn.pomelo.secondskill.mapper.UserInfoMapper;
import cn.pomelo.secondskill.service.UserInfoService;
@Service
public class UserInfoServiceImpl implements UserInfoService{

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public int deleteByPrimaryKey(Integer id,String openid) {
        return userInfoMapper.deleteByPrimaryKey(id,openid);
    }

    @Override
    public int insert(UserInfo record) {
        return userInfoMapper.insert(record);
    }

    @Override
    public int insertSelective(UserInfo record) {
        return userInfoMapper.insertSelective(record);
    }

    @Override
    public UserInfo selectByPrimaryKey(Integer id,String openid) {
        return userInfoMapper.selectByPrimaryKey(id,openid);
    }

    @Override
    public int updateByPrimaryKeySelective(UserInfo record) {
        return userInfoMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(UserInfo record) {
        return userInfoMapper.updateByPrimaryKey(record);
    }

    @Override
    public UserInfo login(String openid) {
        UserInfo userInfo = new UserInfo();
        userInfo.setOpenid(openid);
        userInfo.setUsername(ObjectId.next());
        int i = insertSelective(userInfo);
        return i > 0 ? userInfo : null;
    }

    @Override
    public UserInfo selectByOpenid(String openid) {
        return userInfoMapper.selectByOpenid(openid);
    }

}
